package com.sdry.web.controller.phone;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sdry.base.BaseController;
import com.sdry.entity.PartInfo;
import com.sdry.entity.PartInfoExample;
import com.sdry.service.PartInfoService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 备品备件
 * 
 * @AUTHOR HACKER
 */
@Api(value = "备品备件")
@Controller
@RequestMapping("/base/part/phone")
public class PartInfoPhoneController extends BaseController {

	@Autowired
	private PartInfoService partInfoService;

	/**
	 * 列表
	 * @param offset
	 * @param limit
	 * @param search
	 * @param sort
	 * @param order
	 * @return
	 */
	@ApiOperation(value = "列表")
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ResponseBody
	public Object list(@RequestParam(required = false, defaultValue = "0") int index,
			@RequestParam(required = false, defaultValue = "10") int limit,
			@RequestParam(required = false, defaultValue = "") String search,
			@RequestParam(required = false) String sort,
			@RequestParam(required = false) String order) {
		PartInfoExample partInfoExample = new PartInfoExample();
		if (!StringUtils.isBlank(sort) && !StringUtils.isBlank(order)) {
			partInfoExample.setOrderByClause(sort + " " + order);
		}
		if (StringUtils.isNotBlank(search)) {
			partInfoExample.or().andModelLike("%" + search + "%");
		}
		// long total = partInfoService.countByExample(partInfoExample);
		int offset = (index - 1) * limit;
		List<PartInfo> rows = partInfoService.selectByExampleForOffsetPage(partInfoExample, offset, limit);
		Map<String, Object> result = new HashMap<>();
		result.put("status", "1");
		result.put("data", rows);
		return result;
	}

}
